package model;

/**
 * Order.java
 * Purpose: Represents an order.
 * 
 * @author Hans Brems
 * @version 0.1 10/01/2012
 */

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Order {
	/* Identifier of the order. */
	private long id;
	/* Customer */
	private Customer customer;
	/* Date when the product was ordered */
	private Date orderDate;
	/* Order lines of the order */
	private List<OrderLine> orderLines;
	/* The id of the customer */
	private long customerId;
	
	/** Constructs a new order */
	public Order() {
		this.orderLines = new ArrayList<OrderLine>();
	}
	
	/** Constructs a new order */
	public Order(long id, Date orderDate) {
		this.id = id;
		this.orderDate = orderDate;
		this.orderLines = new ArrayList<OrderLine>();
	}

	/** Returns the id of the order */
	public long getId() {
		return id;
	}

	/** Sets the id of the order */
	public void setId(long id) {
		this.id = id;
	}
	
	/** Returns the customer of the order */
	public Customer getCustomer() {
		return customer;
	}

	/** Sets the customer of the order */
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	/** Returns the customer id */
	public long getCustomerId() {
		return customerId;
	}
	
	/** Sets the customer id */
	public void setCustomerId(long customerId) {
		this.customerId = customerId;
	}

	/** Returns the order date of the order */
	public Date getOrderDate() {
		return orderDate;
	}

	/** Sets the order date of the order */
	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}
	
	/** Adds an order line to the order */
	public void addOrderLine(OrderLine orderLine) {
		this.orderLines.add(orderLine);
	}
	
	/** Removes an order line from the order */
	public void removeOrderLine(OrderLine orderLine) {
		this.orderLines.remove(orderLine);
	}
	
	/** Checks if the order contains a certain line */
	public boolean containsOrderLine(OrderLine orderLine) {
		return this.orderLines.contains(orderLine);
	}
	
	/** Returns a string representation of the order */
	@Override
	public String toString() {
		return String.format("Order: %s - Customer: %s", this.id, this.customer.getName());
	}
}
